﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kunlun.Models;
using Kunlun.BusinessLogic;
namespace Kunlun.Areas.Recommend.Controllers
{
    public class IndexController : Controller
    {
        //
        // GET: /Recommend/Index/
        KunLunEntities entities = new KunLunEntities();
        public ActionResult Index(int id)
        {
             KunlunCookies.Expirestime = 43200;
             KunlunCookies.WriteCookie("Recomand", id.ToString());

             Consumer user = entities.Consumers.FirstOrDefault(u => u.ID == id);
             string ip = Request.UserHostAddress;
             var pic = entities.Consumer_pic.Where(p => p.UserID == id).Take(12);
             if (user.RealName != "")
                 {
                 ViewBag.UserName = user.RealName;
                 }
             else {
                    ViewBag.UserName = user.UserName;
                 }
             Models.Recommend commend = new Models.Recommend();
             commend.Register = 0;
             commend.UserID = id;
             commend.UserIP = ip;
             commend.VisitTime = DateTime.Now;
            
             user.Scoring = user.Scoring + 1;             
             entities.Recommend.Add(commend);
             entities.SaveChanges();
             KunlunCookies.WriteCookie("RecomandID", commend.ID.ToString());
             return View(pic);
        }
    }
}
